<%@page import="com.wanmait.hotelManage.vo.Userinfo"%>
<%@page import="java.util.List"%>
<%@page import="com.wanmait.hotelManage.vo.Order"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <% String path=request.getContextPath(); %>
    <% List<Order> orders=(List<Order>)request.getAttribute("orders"); %> 
    <% Userinfo userinfo=(Userinfo)session.getAttribute("userinfo"); 
	List<Double> prices=(List<Double>)request.getAttribute("prices");
    
    %>
<!DOCTYPE html>
<head>
<jsp:include page="/FrontDesk/center/header.jsp"></jsp:include>
			<!-- /Sidebar -->
			
			<!-- Page Wrapper -->
            <div class="page-wrapper">
			
                <div class="content container-fluid">
					
					<!-- Page Header -->
					<div class="page-header">
						<div class="row">
							<div class="col-sm-12">
								<h3 class="page-title">你的订单</h3>
							
							</div>
						</div>
					</div>
					<!-- /Page Header -->
					<div class="row">
						<div class="col-md-12">
						
							<!-- Recent Orders -->
							<div class="card card-table">
								<div class="card-header">
								
									<h4 class="card-title">订单列表</h4>
								</div>
								<div class="card-body">
									<div class="table-responsive">
										<table class="table table-hover table-center mb-0">
											<thead>
												<tr>
												<th>姓名</th>
												<th>电话</th>
													<th>房型</th>
												
													<th>订单时间</th>
													<th>房间始终日期</th>
													<th>退订</th>
													<th class="text-right">价钱</th>
												</tr>
											</thead>
											<% for(int i=0;i<orders.size();i++){ %>
											<%-- <tbody>
											<% for(Order order:orders){ %> --%>
											<tbody class="tbody">
												<tr>
												<td>
														<h2 id="t<%=orders.get(i).getId() %>" class="table-avatar"><%=orders.get(i).getName() %></h2>
														</td>
														<td>
														<h2 id="t<%=orders.get(i).getId() %>" class="table-avatar"><%=userinfo.getTelephoneNumber() %></h2>
														</td>
													<td>
														<h2 id="t1<%=orders.get(i).getId() %>" class="table-avatar"><%=orders.get(i).getRoomType().getTitle() %></h2>
													</td>
													  
													  
													<td class="orderTimes">
														<h2 id="orderTime" class="table-avatar" name="orderTime"><%=orders.get(i).getInputTime() %></h2>
													</td>
													<td><%=orders.get(i).getStartTime() %> <span class="text-primary d-block"><%=orders.get(i).getEndTime() %></span></td>
													<td>
													<% if(orders.get(i).getEnable()) {%>
													<% if(orders.get(i).getCar()){ %>
														<div class="status-toggle" id=id="status-toggle"+<%=orders.get(i).getId()%>>
														<input type="hidden" id="id" value="<%=orders.get(i).getId() %>" >
															<input type="checkbox" id="status_1" class="check" checked>
															<input type="button" value="退     订" id="but" class="butt">
															<input type="button" value="评    论" id="combut" class="commentbut">
															<input type="button" value="已订车">
																<a class="link-del" id="de<%=orders.get(i).getId() %>" href="javaScript:void(0)">删除</ a>
														</div>
														<%} 
													else{ %>
														 <div class="status-toggle" id="status-toggle"+<%=orders.get(i).getId()%>>
														<input type="hidden" value="<%=orders.get(i).getId() %>" >
															<input type="checkbox" id="status_1" class="check" checked>
															<input type="button" value="退     订" id="but" class="butt">
															<input type="button" value="评    论" id="combut" class="commentbut">
														   	<a class="link-del" id="de<%=orders.get(i).getId() %>" href="javaScript:void(0)">删除</ a>
														</div>
															
													<%} %>	
														<%} else{%>
														<div class="status-toggle" id="status-toggle"+<%=orders.get(i).getId()%>>
														<input type="hidden" value="<%=orders.get(i).getId() %>" name="id" >
															<input type="checkbox" id="status_1" class="check" checked>
															<input type="button" disabled="true" value="已退订" id="but" class="butt">
														    	<a class="link-del" id="de<%=orders.get(i).getId() %>" href="javaScript:void(0)">删除</ a>  
														</div>
														<%} %>
													</td>
													<td class="text-right">
														<%=prices.get(i) %>
													</td>
												</tr>
												<%} %>
											</tbody>
										</table>
									</div>
								</div>
							</div>
							<!-- /Recent Orders -->
							
						</div>
					</div>
					
				</div>			
			</div>
			<script type="WebContent/static/js/jquery-3.5.1.min.js"></script>
			<script >
			
			
			
			
			</script>
			<!-- /Page Wrapper -->
		<script src="<%=request.getContextPath()%>/static/js/jquery-3.5.1.min.js"></script>
		<script>
		$(function(){
			$(".butt").click(function(){
				var ids=$(this).prev().prev().val();
				
					var c= $(this).parent().parent().prev().prev().children().text();
					var time = new Date();   // 程序计时的月从0开始取值后+1   
					var m = time.getMonth() + 1;   
					var t = time.getFullYear() + "-" + m + "-"     
					+ time.getDate() + " " + time.getHours() + ":"     
					+ time.getMinutes() + ":" + time.getSeconds();   
					
				//	date = date.substring(0,19);    
					date = c.replace(/-/g,'/'); 
					var timestamp = new Date(date).getTime();
					datea = t.replace(/-/g,'/'); 
					var timestampa = new Date(datea).getTime();
					if(timestampa-timestamp>800000){
						
						alert("已经超时不可以退订");
					}
					else{
					$.ajax({
						url:"<%=path%>/OrderServlet",
						data:{"action":"tui","id":ids} ,
						success:function(data){
							
						}
					})	
					$(this).val("已退订")
					$(this).attr("disabled",true)
					}
					
			})
	
			$(".commentbut").click(function(){
					var ids=$(this).prev().prev().prev().val();
					
					var title=$("#t1"+ids).html();
					
					$.ajax({
						url:"<%=path%>/OrderServlet",
						data:{"action":"comment","id":ids} ,
						success:function(data){
						
							if(data=="ok"){
							 window.location.href="<%=request.getContextPath()%>/roomListServlet?action=comment&roomTypeName="+title;
							}
							else{
								alert("订单未完成")	
							}
							
						
				}
					})	
					
					
		})		
			
		})	
		$(function(){
		
				$(".tbody").on("click",".link-del",function(){
					  if(!window.confirm("你确定要删除吗")){
					   return false;
					  }
					  
					  var id=$(this).attr("id").substring(2);
					  var th = $(this);
					 
					 
					  $.ajax({
					   url:"<%=path%>/OrderServlet?action=de",
					   data:{"id":id},
					   success:function(){
					//    $("#status-toggle"+id).remove();
						   th.parent().parent().parent().parent().remove();
					   }
					  }) 
					 })
			})
					
					
			
					
		
			
		
			
		
		
		
		</script>
		
        </div>
		<!-- /Main Wrapper -->
		
		<!-- jQuery -->
        <script src="assets/js/jquery-3.2.1.min.js"></script>
		
		<!-- Bootstrap Core JS -->
        <script src="assets/js/popper.min.js"></script>
        <script src="assets/js/bootstrap.min.js"></script>
		
		<!-- Slimscroll JS -->
        <script src="assets/plugins/slimscroll/jquery.slimscroll.min.js"></script>
		
		<script src="assets/plugins/raphael/raphael.min.js"></script>    
		<script src="assets/plugins/morris/morris.min.js"></script>  
		<script src="assets/js/chart.morris.js"></script>
		
		<!-- Custom JS -->
		<script  src="assets/js/script.js"></script>
		
    </body>
</html>